﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Container.Library;
using Microsoft.AspNetCore.Mvc;
using Project.Logic;
using Project.Model;
using Tool.Model;
using Web.Manage.App_Start;

namespace Web.Manage.Areas.Staff.Controllers
{
    /// <summary>
    /// 员工考勤明细操作控制器
    /// </summary>
    [Area("Staff")]
    public class SalaryController : BaseController
    {

        private readonly IEmployeeService employeeService = null;//员工管理逻辑

        public SalaryController()
        {
            //员工管理逻辑注入
            employeeService = UnityCIContainer.Instance.GetService<IEmployeeService>();
        }

        #region 界面

        /// <summary>
        /// 列表界面
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyView)]
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 结算工资界面
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public IActionResult SettlementInfo()
        {
            return View();
        }

        #endregion

        #region 查询

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult LoadEmployeeSalaryList()
        {
            var resultInfo = new ResultJsonInfo<List<SalaryInfoQueryResponse>>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<SalaryQueryRequest>>();

                resultInfo = employeeService.LoadEmployeeSalaryList(parametersInfo);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Msg = ex.Message;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }

        #endregion

        #region 结算工资

        /// <summary>
        /// 结算工资
        /// </summary>
        /// <returns></returns>
        [UserAuthorization(true, FunctionValidateType.VerifyLoggedIn)]
        public ActionResult Settlement()
        {
            var resultInfo = new ResultJsonInfo<int>();
            try
            {
                //实体接收数据
                var parametersInfo = DeserializeRequestData<ParametersInfo<SalarySettlementRequest>>();

                resultInfo = employeeService.Settlement(parametersInfo.parameters);
            }
            catch (Exception ex)
            {
                resultInfo.Success = false;
                resultInfo.Msg = ex.Message;
                resultInfo.Excep = ex;
            }
            return ReturnContent(resultInfo);
        }
        #endregion
    }
}